package com.zhhs.galaxyott.sharepreference;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

public class SharedPrefHelper {
    private static final String TAG = SharedPrefHelper.class.getSimpleName();
    /**
     * SharedPreferences的名字
     */
    private static final String SP_FILE_NAME = "APPLICATION_SP";
    private static SharedPrefHelper sharedPrefHelper = null;
    private static SharedPreferences sharedPreferences;

    private static final String KEY_PROVINCE = "province";
    private static final String KEY_CITY = "city";

    public static synchronized SharedPrefHelper getInstance(Context c) {
        if (null == sharedPrefHelper) {
            sharedPrefHelper = new SharedPrefHelper(c);
        }
        return sharedPrefHelper;
    }

    private SharedPrefHelper(Context c) {
        sharedPreferences = c.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
    }

    public static SharedPreferences sp(Context c) {
        return c.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
    }

    /**
     * 应用第一次安装，也就是第一次启动
     * 
     */
    public void setInstall(boolean isFirst) {
        sharedPreferences.edit().putBoolean("install", isFirst).commit();
    }

    public boolean getInstall() {
        return sharedPreferences.getBoolean("install", false);
    }

    /**
     * 记住当前播放时长
     * 
     */
    public void setOffsetTime(String offsetTime) {
        sharedPreferences.edit().putString("offsetTime", offsetTime).commit();
    }

    public String getOffsetTime() {
        String temp = sharedPreferences.getString("offsetTime", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    /**
     * 记住用户id即smartcard
     * 
     */
    public void setsmartcard(String userid) {
        sharedPreferences.edit().putString("smartcard", userid).commit();
    }

    public String getsmartcard() {
        String temp = sharedPreferences.getString("smartcard", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    public void cleansmartcard() {
        sharedPreferences.edit().putString("smartcard", "-1").commit();
    }

    /**
     * 记住epg地址
     * 
     */
    public void setepgUrl(String epgUrl) {
        sharedPreferences.edit().putString("epgUrl", epgUrl).commit();
    }

    public String getepgUrl() {
        String temp = sharedPreferences.getString("epgUrl", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    public void cleanepgUrl() {
        sharedPreferences.edit().putString("epgUrl", "-1").commit();
    }

    /**
     * 记住浏览器Cookies
     * 
     */
    public void setCookies(String cookies) {
        sharedPreferences.edit().putString("cookies", cookies).commit();
    }

    public String getCookies() {
        String temp = sharedPreferences.getString("cookies", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    public void cleanCookies() {
        sharedPreferences.edit().putString("cookies", "-1").commit();
    }

    /**
     * 记住用户名即userid
     * 
     */
    public void setStbid(String stbid) {
        sharedPreferences.edit().putString("stbid", stbid).commit();
    }

    public String getStbid() {
        String temp = sharedPreferences.getString("stbid", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    public void cleanStbid() {
        sharedPreferences.edit().putString("stbid", "-1").commit();
    }

    /**
     * 记住用户token
     * 
     */
    public void setToken(String token) {
        sharedPreferences.edit().putString("token", token).commit();
    }

    public String getToken() {
        return sharedPreferences.getString("token", "");
    }

    public void cleanToken() {
        sharedPreferences.edit().putString("token", "").commit();
    }

    /**
     * 是否是VIP
     * 
     */
    public void setIsVip(boolean isVip) {
        sharedPreferences.edit().putBoolean("isVip", isVip).commit();
    }

    public boolean getIsVip() {
        return sharedPreferences.getBoolean("isVip", false);
    }

    public void cleanIsVip() {
        sharedPreferences.edit().putBoolean("isVip", false).commit();
    }

    /**
     * 套餐业务是否上线
     * 
     */
    public void setIsComboOnline(boolean isComboOnline) {
        sharedPreferences.edit().putBoolean("isComboOnline", isComboOnline).commit();
    }

    public boolean getIsComboOnline() {
        return sharedPreferences.getBoolean("isComboOnline", false);
    }

    public void cleanIsComboOnline() {
        sharedPreferences.edit().putBoolean("isComboOnline", false).commit();
    }

    /**
     * 记住用户手机号码
     * 
     */
    public void setPhoneNumber(String phone) {
        sharedPreferences.edit().putString("phone", phone).commit();
    }

    public String getPhoneNumber() {
        String temp = sharedPreferences.getString("phone", "-1");
        if (TextUtils.isEmpty(temp)) {
            return "-1";
        }
        return temp;
    }

    public void cleanPhoneNumber() {
        sharedPreferences.edit().putString("phone", "-1").commit();
    }

    /**
     * 是否登录
     * 
     */
    public void setIsLogin(boolean isLogin) {
        sharedPreferences.edit().putBoolean("isLogin", isLogin).commit();
    }

    public boolean getIsLogin() {
        return sharedPreferences.getBoolean("isLogin", false);
    }

    public void cleanIsLogin() {
        sharedPreferences.edit().putBoolean("isLogin", false).commit();
    }

}
